using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using DOMercury.Interfaces;

namespace DOMercury.Items
{
    /// <summary>
    /// An IItem wrapper around a path.  Used only to populate an ItemsList.
    /// </summary>
    public class PathItem : IItem, IComparable
    {
        private string path;
        private string displayname;
        private string type = "folder";
        /// <summary>
        /// The PathItem Constructor
        /// </summary>
        /// <param name="Path">The path</param>
        /// <param name="DisplayItem">The name displayed to the user</param>
        public PathItem(string Path, string DisplayItem)
        {
            path = Path.Replace(":\\\\", ":\\");
            displayname = DisplayItem;
            findtype();
        }

        private void findtype()
        {
            if (Directory.Exists(path))
            {
                type = "folder";
            }
            else if (System.IO.Path.HasExtension(path))
            {
                type = System.IO.Path.GetExtension(path);
            }
        }

        /// <summary>
        /// The Path
        /// </summary>
        public string Path
        {
            get
            {
                return path;
            }
            set
            {
                path = value;
                findtype();
            }
        }

        /// <summary>
        /// Returns the physical path
        /// </summary>
        public string DisplayDesc
        {
            get
            {
                return Path;
            }
        }

        /// <summary>
        /// The representation of the PathItem displayed to the user
        /// </summary>
        public string DisplayName
        {
            get
            {
                return displayname;
            }
            set
            {
                displayname = value;
            }
        }

        /// <summary>
        /// the extension of the file or "folder" if a directory
        /// </summary>
        public string ItemType
        {
            get
            {
                return type;
            }
        }

        public int CompareTo(object obj)
        {
            return DisplayName.CompareTo(((IItem)(obj)).DisplayName);
        }
    }
}
